using System;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;

namespace AntEater.Integration
{
    /// <summary>
    /// Wrapper class for listening to the document events
    /// </summary>
    internal class ProjectListener : IVsTrackProjectDocumentsEvents2
    {
        /// <summary>
        /// A document or folder was added to the solution
        /// </summary>
        public event EventHandler<EventArgs> ItemAdded;

        /// <summary>
        /// A document or folder was deleted from the solution
        /// </summary>
        public event EventHandler<EventArgs> ItemDeleted;

        /// <summary>
        /// A document or folder was renamed
        /// </summary>
        public event EventHandler<EventArgs> ItemRenamed;

        /// <summary>
        /// Called when [after add directories ex].
        /// </summary>
        /// <param name="cProjects">The c projects.</param>
        /// <param name="cDirectories">The c directories.</param>
        /// <param name="rgpProjects">The RGP projects.</param>
        /// <param name="rgFirstIndices">The rg first indices.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnAfterAddDirectoriesEx(int cProjects, int cDirectories, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, VSADDDIRECTORYFLAGS[] rgFlags) {
            if (ItemAdded != null) {
                ItemAdded(this, new EventArgs());
            }
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [after add files ex].
        /// </summary>
        /// <param name="cProjects">The c projects.</param>
        /// <param name="cFiles">The c files.</param>
        /// <param name="rgpProjects">The RGP projects.</param>
        /// <param name="rgFirstIndices">The rg first indices.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnAfterAddFilesEx(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, VSADDFILEFLAGS[] rgFlags) {
            if (ItemAdded != null) {
                ItemAdded(this, new EventArgs());
            }
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [after remove directories].
        /// </summary>
        /// <param name="cProjects">The c projects.</param>
        /// <param name="cDirectories">The c directories.</param>
        /// <param name="rgpProjects">The RGP projects.</param>
        /// <param name="rgFirstIndices">The rg first indices.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnAfterRemoveDirectories(int cProjects, int cDirectories, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, VSREMOVEDIRECTORYFLAGS[] rgFlags) {
            if (ItemDeleted != null) {
                ItemDeleted(this, new EventArgs());
            }
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [after remove files].
        /// </summary>
        /// <param name="cProjects">The c projects.</param>
        /// <param name="cFiles">The c files.</param>
        /// <param name="rgpProjects">The RGP projects.</param>
        /// <param name="rgFirstIndices">The rg first indices.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnAfterRemoveFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, VSREMOVEFILEFLAGS[] rgFlags) {
            if (ItemDeleted != null) {
                ItemDeleted(this, new EventArgs());
            }
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [after rename directories].
        /// </summary>
        /// <param name="cProjects">The c projects.</param>
        /// <param name="cDirs">The c dirs.</param>
        /// <param name="rgpProjects">The RGP projects.</param>
        /// <param name="rgFirstIndices">The rg first indices.</param>
        /// <param name="rgszMkOldNames">The RGSZ mk old names.</param>
        /// <param name="rgszMkNewNames">The RGSZ mk new names.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnAfterRenameDirectories(int cProjects, int cDirs, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEDIRECTORYFLAGS[] rgFlags) {
            if (ItemRenamed != null) {
                ItemRenamed(this, new EventArgs());
            }
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [after rename files].
        /// </summary>
        /// <param name="cProjects">The c projects.</param>
        /// <param name="cFiles">The c files.</param>
        /// <param name="rgpProjects">The RGP projects.</param>
        /// <param name="rgFirstIndices">The rg first indices.</param>
        /// <param name="rgszMkOldNames">The RGSZ mk old names.</param>
        /// <param name="rgszMkNewNames">The RGSZ mk new names.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnAfterRenameFiles(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames, VSRENAMEFILEFLAGS[] rgFlags) {
            if (ItemRenamed != null) {
                ItemRenamed(this, new EventArgs());
            }
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [after SCC status changed].
        /// </summary>
        /// <param name="cProjects">The c projects.</param>
        /// <param name="cFiles">The c files.</param>
        /// <param name="rgpProjects">The RGP projects.</param>
        /// <param name="rgFirstIndices">The rg first indices.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgdwSccStatus">The RGDW SCC status.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnAfterSccStatusChanged(int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments, uint[] rgdwSccStatus) {
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [query add directories].
        /// </summary>
        /// <param name="pProject">The p project.</param>
        /// <param name="cDirectories">The c directories.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <param name="pSummaryResult">The p summary result.</param>
        /// <param name="rgResults">The rg results.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnQueryAddDirectories(IVsProject pProject, int cDirectories, string[] rgpszMkDocuments, VSQUERYADDDIRECTORYFLAGS[] rgFlags, VSQUERYADDDIRECTORYRESULTS[] pSummaryResult, VSQUERYADDDIRECTORYRESULTS[] rgResults) {
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [query add files].
        /// </summary>
        /// <param name="pProject">The p project.</param>
        /// <param name="cFiles">The c files.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <param name="pSummaryResult">The p summary result.</param>
        /// <param name="rgResults">The rg results.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnQueryAddFiles(IVsProject pProject, int cFiles, string[] rgpszMkDocuments, VSQUERYADDFILEFLAGS[] rgFlags, VSQUERYADDFILERESULTS[] pSummaryResult, VSQUERYADDFILERESULTS[] rgResults) {
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [query remove directories].
        /// </summary>
        /// <param name="pProject">The p project.</param>
        /// <param name="cDirectories">The c directories.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <param name="pSummaryResult">The p summary result.</param>
        /// <param name="rgResults">The rg results.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnQueryRemoveDirectories(IVsProject pProject, int cDirectories, string[] rgpszMkDocuments, VSQUERYREMOVEDIRECTORYFLAGS[] rgFlags, VSQUERYREMOVEDIRECTORYRESULTS[] pSummaryResult, VSQUERYREMOVEDIRECTORYRESULTS[] rgResults) {
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [query remove files].
        /// </summary>
        /// <param name="pProject">The p project.</param>
        /// <param name="cFiles">The c files.</param>
        /// <param name="rgpszMkDocuments">The RGPSZ mk documents.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <param name="pSummaryResult">The p summary result.</param>
        /// <param name="rgResults">The rg results.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnQueryRemoveFiles(IVsProject pProject, int cFiles, string[] rgpszMkDocuments, VSQUERYREMOVEFILEFLAGS[] rgFlags, VSQUERYREMOVEFILERESULTS[] pSummaryResult, VSQUERYREMOVEFILERESULTS[] rgResults) {
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [query rename directories].
        /// </summary>
        /// <param name="pProject">The p project.</param>
        /// <param name="cDirs">The c dirs.</param>
        /// <param name="rgszMkOldNames">The RGSZ mk old names.</param>
        /// <param name="rgszMkNewNames">The RGSZ mk new names.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <param name="pSummaryResult">The p summary result.</param>
        /// <param name="rgResults">The rg results.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnQueryRenameDirectories(IVsProject pProject, int cDirs, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEDIRECTORYFLAGS[] rgFlags, VSQUERYRENAMEDIRECTORYRESULTS[] pSummaryResult, VSQUERYRENAMEDIRECTORYRESULTS[] rgResults) {
            return VSConstants.S_OK;
        }

        /// <summary>
        /// Called when [query rename files].
        /// </summary>
        /// <param name="pProject">The p project.</param>
        /// <param name="cFiles">The c files.</param>
        /// <param name="rgszMkOldNames">The RGSZ mk old names.</param>
        /// <param name="rgszMkNewNames">The RGSZ mk new names.</param>
        /// <param name="rgFlags">The rg flags.</param>
        /// <param name="pSummaryResult">The p summary result.</param>
        /// <param name="rgResults">The rg results.</param>
        /// <returns></returns>
        int IVsTrackProjectDocumentsEvents2.OnQueryRenameFiles(IVsProject pProject, int cFiles, string[] rgszMkOldNames, string[] rgszMkNewNames, VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult, VSQUERYRENAMEFILERESULTS[] rgResults) {
            return VSConstants.S_OK;
        }
    }
}
